package gof_001_创建型_Create.gof_001_单例_Singleton.gof_011_Serializable;

import java.io.Serializable;

//为了能够 Student 序列化,实现 Serializable 接口
public class Student implements Serializable {
    private volatile static Student student = null;

    public static Student getInstance(){
        if(student == null){
            synchronized(Student.class){
                if(student == null){
                    student = new Student();
                }
            }
        }
        return student;
    }

    /**
     * 防止序列化破坏单例
     * @return
     */
    public Object readResolve(){
        return student;
    }
}
